package blazingbubble.network.game.strategy;

import moltencore.game.CannonData;
import moltencore.network.protocol.CannonNewTargetDirection;
import spark.network.protocol.Response;
import spark.network.strategy.IProtocolHandleStrategy;
import spark.network.protocol.Base;
import spark.math.Vector2;
import org.apache.log4j.Logger;
import blazingbubble.game.Game;
import spark.utility.OutWrapper;

import java.util.Collection;

public class CannonNewTargetDirectionStrategy implements IProtocolHandleStrategy<CannonNewTargetDirection> {
	private Logger logger = Logger.getLogger(CannonNewTargetDirectionStrategy.class);

	private Game game;

	public CannonNewTargetDirectionStrategy(Game game) {
		this.game = game;
	}

	@Override
	public void handle(CannonNewTargetDirection packet, OutWrapper<Response> acknowledgement, Collection<Base> additionalData) {
		int playerPositionIndex = game.getPlayer(packet.getClientId()).getPositionIndex();
		CannonData cannonData = game.getFieldByClientId(packet.getClientId()).getCannonData(playerPositionIndex);
		cannonData.getTarget().copy(packet.getAimVector());
	}
}